\hypertarget{group__nxbot__ir}{
\section{IR Library}
\label{group__nxbot__ir}\index{IR Library@{IR Library}}
}


Interrupt IR library for checking the state of the ir sensors in NXBOT.  
\subsection*{Defines}
\begin{DoxyCompactItemize}
\item 
\#define \hyperlink{group__nxbot__ir_ga7642f709b3d5ff5b69f9086bd11818ba}{IR\_\-80N}~0
\begin{DoxyCompactList}\small\item\em Constant to access the IR located at -\/80°. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__ir_ga9203133eca481279b019c55d815c5853}{IR\_\-45N}~1
\begin{DoxyCompactList}\small\item\em Constant to access the IR located at -\/45°. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__ir_gad4a271f95e452860d1a073e6f35392ea}{IR\_\-10N}~2
\begin{DoxyCompactList}\small\item\em Constant to access the IR located at -\/10°. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__ir_gac85fda4de290b519a22b0629939fc70e}{IR\_\-10P}~3
\begin{DoxyCompactList}\small\item\em Constant to access the IR located at 10°. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__ir_ga3b7a6c5d65425db436c3187327c8fc88}{IR\_\-45P}~4
\begin{DoxyCompactList}\small\item\em Constant to access the IR located at 45°. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__ir_gac49fd13d4e542d198467adef92cc2058}{IR\_\-80P}~5
\begin{DoxyCompactList}\small\item\em Constant to access the IR located at 80°. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \hyperlink{group__nxbot__ir_gab53f468c7a3aab848dba9c2fbcf4f202}{ir\_\-init} (void)
\begin{DoxyCompactList}\small\item\em Hardware initialization for the ir module. \item\end{DoxyCompactList}\item 
unsigned char \hyperlink{group__nxbot__ir_gad42a07fba8fa150d13300945c93eae77}{ir\_\-read} (void)
\begin{DoxyCompactList}\small\item\em Read the IR states. \item\end{DoxyCompactList}\item 
void \hyperlink{group__nxbot__ir_ga599502bbc98183534eb3e7a82c9a702b}{ir\_\-activate} (unsigned char ir, unsigned char en)
\begin{DoxyCompactList}\small\item\em (De)activates a specific IR module. \item\end{DoxyCompactList}\item 
void \hyperlink{group__nxbot__ir_gaae0e6a1f7cf0f3c9e28c8da19b4a02f0}{ir\_\-activateAll} (unsigned char en)
\begin{DoxyCompactList}\small\item\em (De)activates all IR modules. \item\end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Interrupt IR library for checking the state of the ir sensors in NXBOT. 
\begin{DoxyCode}
 #include <ir.h> 
\end{DoxyCode}
 This module uses the I/O pins of the ATmega1281 microcontroller for accesing the IR modules of NXBot. Each IR module is controlled by two signals: {\itshape Emitter\/} and {\itshape Receiver\/}. The emitter signal should be modulated. The carrier signal uses a 40 kHz frequenzy, which is generated by external hardware. The modulated signal should fulfill a period time of 1600 us, where in the first 600 us the signal should stay HIGH (5V), and in the remaining 1000 us the signal should stay LOW (0V). In order to do that, the modulated signal is generated by the timer5 of the microcontroller. It uses the {\itshape Output Compare\/} configuration in order to generate a signal with this specific duty cicle. For more information, see datasheet of GP1UD28YK device, which is the receiver used in the IR hardware. Because of the use of timer5, the readings will only be done when interrupts are active. Therefore, it is necessary to enable interrupts, for example via the {\itshape sei()\/} function. 

\subsection{Define Documentation}
\hypertarget{group__nxbot__ir_gad4a271f95e452860d1a073e6f35392ea}{
\index{nxbot\_\-ir@{nxbot\_\-ir}!IR\_\-10N@{IR\_\-10N}}
\index{IR\_\-10N@{IR\_\-10N}!nxbot_ir@{nxbot\_\-ir}}
\subsubsection[{IR\_\-10N}]{\setlength{\rightskip}{0pt plus 5cm}\#define IR\_\-10N~2}}
\label{group__nxbot__ir_gad4a271f95e452860d1a073e6f35392ea}


Constant to access the IR located at -\/10°. \begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__ir_ga599502bbc98183534eb3e7a82c9a702b}{ir\_\-activate} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__ir_gac85fda4de290b519a22b0629939fc70e}{
\index{nxbot\_\-ir@{nxbot\_\-ir}!IR\_\-10P@{IR\_\-10P}}
\index{IR\_\-10P@{IR\_\-10P}!nxbot_ir@{nxbot\_\-ir}}
\subsubsection[{IR\_\-10P}]{\setlength{\rightskip}{0pt plus 5cm}\#define IR\_\-10P~3}}
\label{group__nxbot__ir_gac85fda4de290b519a22b0629939fc70e}


Constant to access the IR located at 10°. \begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__ir_ga599502bbc98183534eb3e7a82c9a702b}{ir\_\-activate} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__ir_ga9203133eca481279b019c55d815c5853}{
\index{nxbot\_\-ir@{nxbot\_\-ir}!IR\_\-45N@{IR\_\-45N}}
\index{IR\_\-45N@{IR\_\-45N}!nxbot_ir@{nxbot\_\-ir}}
\subsubsection[{IR\_\-45N}]{\setlength{\rightskip}{0pt plus 5cm}\#define IR\_\-45N~1}}
\label{group__nxbot__ir_ga9203133eca481279b019c55d815c5853}


Constant to access the IR located at -\/45°. \begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__ir_ga599502bbc98183534eb3e7a82c9a702b}{ir\_\-activate} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__ir_ga3b7a6c5d65425db436c3187327c8fc88}{
\index{nxbot\_\-ir@{nxbot\_\-ir}!IR\_\-45P@{IR\_\-45P}}
\index{IR\_\-45P@{IR\_\-45P}!nxbot_ir@{nxbot\_\-ir}}
\subsubsection[{IR\_\-45P}]{\setlength{\rightskip}{0pt plus 5cm}\#define IR\_\-45P~4}}
\label{group__nxbot__ir_ga3b7a6c5d65425db436c3187327c8fc88}


Constant to access the IR located at 45°. \begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__ir_ga599502bbc98183534eb3e7a82c9a702b}{ir\_\-activate} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__ir_ga7642f709b3d5ff5b69f9086bd11818ba}{
\index{nxbot\_\-ir@{nxbot\_\-ir}!IR\_\-80N@{IR\_\-80N}}
\index{IR\_\-80N@{IR\_\-80N}!nxbot_ir@{nxbot\_\-ir}}
\subsubsection[{IR\_\-80N}]{\setlength{\rightskip}{0pt plus 5cm}\#define IR\_\-80N~0}}
\label{group__nxbot__ir_ga7642f709b3d5ff5b69f9086bd11818ba}


Constant to access the IR located at -\/80°. \begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__ir_ga599502bbc98183534eb3e7a82c9a702b}{ir\_\-activate} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__ir_gac49fd13d4e542d198467adef92cc2058}{
\index{nxbot\_\-ir@{nxbot\_\-ir}!IR\_\-80P@{IR\_\-80P}}
\index{IR\_\-80P@{IR\_\-80P}!nxbot_ir@{nxbot\_\-ir}}
\subsubsection[{IR\_\-80P}]{\setlength{\rightskip}{0pt plus 5cm}\#define IR\_\-80P~5}}
\label{group__nxbot__ir_gac49fd13d4e542d198467adef92cc2058}


Constant to access the IR located at 80°. \begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__ir_ga599502bbc98183534eb3e7a82c9a702b}{ir\_\-activate} 
\end{DoxySeeAlso}


\subsection{Function Documentation}
\hypertarget{group__nxbot__ir_ga599502bbc98183534eb3e7a82c9a702b}{
\index{nxbot\_\-ir@{nxbot\_\-ir}!ir\_\-activate@{ir\_\-activate}}
\index{ir\_\-activate@{ir\_\-activate}!nxbot_ir@{nxbot\_\-ir}}
\subsubsection[{ir\_\-activate}]{\setlength{\rightskip}{0pt plus 5cm}void ir\_\-activate (unsigned char {\em ir}, \/  unsigned char {\em en})}}
\label{group__nxbot__ir_ga599502bbc98183534eb3e7a82c9a702b}


(De)activates a specific IR module. The activation permits updating of data coming from this sensor. 
\begin{DoxyParams}{Parameters}
\item[{\em ir}]The desired IR to be (de)activated. You should use the constants denoted by IR\_\-(ANGLE), e.g IR\_\-80N. \item[{\em en}]Defines activation or deactivation of IR. You should use the constants ON and OFF defined globally in the Makefile. \end{DoxyParams}
\hypertarget{group__nxbot__ir_gaae0e6a1f7cf0f3c9e28c8da19b4a02f0}{
\index{nxbot\_\-ir@{nxbot\_\-ir}!ir\_\-activateAll@{ir\_\-activateAll}}
\index{ir\_\-activateAll@{ir\_\-activateAll}!nxbot_ir@{nxbot\_\-ir}}
\subsubsection[{ir\_\-activateAll}]{\setlength{\rightskip}{0pt plus 5cm}void ir\_\-activateAll (unsigned char {\em en})}}
\label{group__nxbot__ir_gaae0e6a1f7cf0f3c9e28c8da19b4a02f0}


(De)activates all IR modules. The activation permits updating of data coming from all sensors. 
\begin{DoxyParams}{Parameters}
\item[{\em en}]Defines activation or deactivation of all IRs. You should use the constants ON and OFF defined globally in the Makefile. \end{DoxyParams}
\hypertarget{group__nxbot__ir_gab53f468c7a3aab848dba9c2fbcf4f202}{
\index{nxbot\_\-ir@{nxbot\_\-ir}!ir\_\-init@{ir\_\-init}}
\index{ir\_\-init@{ir\_\-init}!nxbot_ir@{nxbot\_\-ir}}
\subsubsection[{ir\_\-init}]{\setlength{\rightskip}{0pt plus 5cm}void ir\_\-init (void)}}
\label{group__nxbot__ir_gab53f468c7a3aab848dba9c2fbcf4f202}


Hardware initialization for the ir module. Configures Emitter pins as outputs and Receiver pins as inputs. Disables all IRs and configures timer5 in {\itshape Output Compare\/} mode \hypertarget{group__nxbot__ir_gad42a07fba8fa150d13300945c93eae77}{
\index{nxbot\_\-ir@{nxbot\_\-ir}!ir\_\-read@{ir\_\-read}}
\index{ir\_\-read@{ir\_\-read}!nxbot_ir@{nxbot\_\-ir}}
\subsubsection[{ir\_\-read}]{\setlength{\rightskip}{0pt plus 5cm}unsigned char ir\_\-read (void)}}
\label{group__nxbot__ir_gad42a07fba8fa150d13300945c93eae77}


Read the IR states. Reads the state of all active IRs. Remember to activate the IRs before reading its state. This is done by using \hyperlink{group__nxbot__ir_ga599502bbc98183534eb3e7a82c9a702b}{ir\_\-activate()} function for activating one IR at a time. If you want to activate all of them, use \hyperlink{group__nxbot__ir_gaae0e6a1f7cf0f3c9e28c8da19b4a02f0}{ir\_\-activateAll()} instead.

\begin{DoxyReturn}{Returns}
A byte where the the first four bits represent the bumpers state:
\begin{DoxyItemize}
\item {\bfseries Bit0:} \par
 IR located at -\/80°.
\item {\bfseries Bit1:} \par
 IR located at -\/45°.
\item {\bfseries Bit2:} \par
 IR located at -\/10°.
\item {\bfseries Bit3:} \par
 IR located at +10°.
\item {\bfseries Bit4:} \par
 IR located at +45°.
\item {\bfseries Bit5:} \par
 IR located at +80°. 
\end{DoxyItemize}
\end{DoxyReturn}
